﻿@using BlazingTrails.ComponentLibrary.Map
@inherits TestContext

@code {
    private BunitJSModuleInterop _routeMapModule;
    private JSRuntimeInvocationHandler _routeMapModuleInitializeInvocation;

    public RouteMapTests()
    {
        _routeMapModule = JSInterop.SetupModule();
        _routeMapModuleInitializeInvocation = _routeMapModule.SetupVoid("initialize", _ => true).SetVoidResult();
    }

    [Fact]
    public void InitializesMap_When_ComponentFirstRenders()
    {
        // Arrange / Act
        var cut = Render(@<RouteMap />);

        // Assert
        _routeMapModuleInitializeInvocation.VerifyInvoke("initialize", calledTimes: 1);
    }

    [Fact]
    public void CallsDeleteLastWaypointFunction_When_DeleteLastWaypointButtonClicked()
    {
        // Arrange
        var latLongResult = new LatLong(1m, 2m);
        var plannedInvocation = _routeMapModule.Setup<LatLong>("deleteLastWaypoint", _ => true).SetResult(latLongResult);
        var cut = Render(@<RouteMap />);
        var deleteWaypointButton = cut.Find("button[title=\"Delete last waypoint\"]");

        // Act
        deleteWaypointButton.Click();

        // Assert
        plannedInvocation.VerifyInvoke("deleteLastWaypoint", calledTimes: 1);
    }
}
